
#!/bin/bash

echo "安卓一键模拟器脚本"

work_dir=$(cd $(dirname $0); pwd)
cd ${work_dir}/
pwd

echo "执行查询模拟器列表"

a=`emulator -list-avds`

if [ "$a" = "" ]
then  
   echo "不存在模拟器哦"
  return 
fi

arr=(`echo $a | tr ',' ' '`) 

echo ${arr[*]}


device=${arr[0]}

echo "打开默认模拟器${device}"
# t:  标题  x  执行的命令

# chmod 777 startEmulator.sh 

# ./startEmulator.sh ${device}

#  gnome-terminal -t "start emulator" -x bash -c "sh ./emulator @${a};"

# 检测是否启动成功
b=`adb devices`

echo ${b}

arr2=(`echo $b | tr ',' ' '`) 

if [ 4 -eq ${#arr2[*]} ]; then  
 
 osascript <<END
    tell application "Terminal"

        # do script (("cd pwd"))
        do script "cd \"`pwd`\";emulator @${device};"
    end tell

END
sleep 6s
react-native run-android
else

react-native run-android

fi   




